#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    srand((unsigned)time(nullptr));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_accept_clicked()//同意后就正常修改标签的内容
{
    ui->label->setText("we are best friend!!!");
}


void Widget::on_pushButton_reject_pressed()//拒绝就让按钮乱跳
{
    //1.获取当前窗口的尺寸，防止按钮跑出窗口
    int width=this->geometry().width();
    int height=this->geometry().height();

    //2.获取当前按钮的信息
    QRect rec=ui->pushButton_reject->geometry();
    qDebug()<<rec;

    //3.设置按钮跳转的位置
    int x=rand()%width;  //随机位置，不超过范围即可
    int y=rand()%height;

    //4.将位置设置进按钮里
    ui->pushButton_reject->setGeometry(x,y,rec.width(),rec.height());
}
